package org.example.spring_blog.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.spring_blog.model.BlogInfo;

import java.util.List;

@Mapper
public interface BlogInfoMapper {
    /**
     * 查询所有博客
     * @return
     */
    @Select("select id,title,content,user_id,update_time from blog where delete_flag!=1 order by id desc")
    List<BlogInfo> selectAll();

    /**
     * 根据id查询博客
     * @param id
     * @return
     */
    @Select("select id,title,content,user_id,update_time from blog where id=#{id} and delete_flag!=1")
    BlogInfo selectById(Integer id);

    /**
     * 增加博客
     * @param blogInfo
     * @return
     */
    @Insert("insert into blog (title,content,user_id) values (#{title},#{content},#{userId})")
    Integer insertBlog(BlogInfo blogInfo);

    /**
     * 更新博客
     * @param blogInfo
     * @return
     */
    Integer updateBlog(BlogInfo blogInfo);
}
